package com.feng.vo;

import com.feng.constant.StatusCodeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author: 丰
 * @date: 2022/12/7 15:06
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
public class ResultVo<T> {

    private String msg;
    private Integer code;
    private Integer count;
    private T data;

    public static <T> ResultVo<T> success(T data){
        return new ResultVo<T>(StatusCodeEnum.SUCCESS.getMsg(), StatusCodeEnum.SUCCESS.getCode(), 0, data);
    }

    public static <T> ResultVo<T> failed() {
        return new ResultVo<T>(StatusCodeEnum.FAILED.getMsg(), StatusCodeEnum.FAILED.getCode(), 0, null);
    }

    public static <T> ResultVo<T> failed(T data) {
        return new ResultVo<T>(StatusCodeEnum.FAILED.getMsg(), StatusCodeEnum.FAILED.getCode(), 0, data);
    }

    public static <T> ResultVo<T> systemError() {
        return new ResultVo<T>(StatusCodeEnum.SYSTEMERROR.getMsg(), StatusCodeEnum.SYSTEMERROR.getCode(), 0, null);
    }

    public ResultVo<T> message(String msg){
        this.setMsg(msg);
        return this;
    }

    public ResultVo<T> code(Integer code){
        this.setCode(code);
        return this;
    }

    public ResultVo<T> count(Integer count){
        this.count = count;
        return this;
    }

}
